﻿using MediatR;
using S_Incident.Domains.WorkflowEngine;
using S_Incident.Infrasturctre.DapperInterface;
using S_Incident.Read.API.Application.Commands;

namespace S_Incident.Read.API.Application.CommandsHanders
{
    public class BindFormNameCommandHanders : IRequestHandler<BindFormNameCommand, List<BindFormNameDto>>
    {
        private readonly IDapperFormManagementRepository repository;
        public BindFormNameCommandHanders(IDapperFormManagementRepository repository)
        {
            this.repository = repository;
        }
        /// <summary>
        /// 绑定对应表单名称
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<List<BindFormNameDto>> Handle(BindFormNameCommand request, CancellationToken cancellationToken)
        {
            var smilt = "select * from FormManagement";

            var form = await repository.GetAllAsync(smilt);

            var bindFormNameDtoList = new List<BindFormNameDto>();
            foreach (var formData in form)
            {
                bindFormNameDtoList.Add(new BindFormNameDto
                {
                    value = formData.Id, // 假设 Id 是表单数据对象的 ID 属性
                    txt = formData.FormName // 假设 Name 是表单数据对象的名称属性
                });
            }
            return bindFormNameDtoList;
        }
    }
}
